<%@page contentType="text/html;charset=utf-8" %>
<%@taglib prefix="s" uri="/struts-tags" %>   
<script type="text/javascript">
function sys_saveaccount(type)
{
    var act_id = document.getElementById("act_id").value;
    var act_name = document.getElementById("act_name").value;
    var act_password = document.getElementById("act_password").value;
    var act_role = "";
    var account_type = "";
    if (act_id == "admin")
    {
        act_role = document.getElementById("act_role").value;
        account_type = document.getElementById("account_type").value;
    }
    else
    {
        act_role = dijit.byId("act_role").get('value');
        account_type = dijit.byId("account_type").get('value');
    }

    var channelids = "";
    var count = 0;
    var group = document.getElementsByName('channelid');
    for(var i = 0; i < group.length; i++) 
    { 
       if(group[i].checked) 
       {
    	   if (count > 0)
    		   channelids += "&";
    	   channelids += "channelIds[" + count + "]=" + group[i].value;
    	   count++;
       }
    } 

    var merchantids = "";
    count = 0;
    group = document.getElementsByName('merchantid');
    for(var i = 0; i < group.length; i++) 
    { 
       if(group[i].checked) 
       {
           if (count > 0)
        	   merchantids += "&";
           merchantids += "merchantIds[" + count + "]=" + group[i].value;
           count++;
       }
    } 

    var spids = "";
    count = 0;
    group = document.getElementsByName('spid');
    for(var i = 0; i < group.length; i++) 
    { 
       if(group[i].checked) 
       {
           if (count > 0)
        	   spids += "&";
           spids += "spIds[" + count + "]=" + group[i].value;
           count++;
       }
    } 

    var cpids = "";
    count = 0;
    group = document.getElementsByName('cpid');
    for(var i = 0; i < group.length; i++) 
    { 
       if(group[i].checked) 
       {
           if (count > 0)
        	   cpids += "&";
           cpids += "cpIds[" + count + "]=" + group[i].value;
           count++;
       }
    } 

    if (act_id == null || act_id == "" || 
            act_name == null || act_name == "" || 
            act_password == null || act_password == "" || 
            act_role == null || act_role == "" || 
            account_type == null || account_type == "")
    {
        alert("信息不完整！");
        return false;
    }

    if (!confirm("确定继续？"))
    {
        return false;
    }
    var url = "rs/account/save.do";
    var content = "type=" + type
                + "&account.id=" + act_id
                + "&account.name=" + act_name
                + "&account.password=" + act_password
                + "&account.roleId=" + act_role
                + "&account.type=" + account_type
                + "&" + channelids
                + "&" + merchantids
                + "&" + spids
                + "&" + cpids;
    var objectid = "sys_account";
    sendXMLHttpRequest(url, content, objectid); 
}

function sys_listaccount()
{
    var url = "rs/account/list.do";
    var content = "";
    var objectid = "content";
    sendXMLHttpRequest(url, content, objectid); 
}
</script>
 <table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="5"></td>
    <td>   
  <form id="myform">
  <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td colspan="3">
        <table width="100%"  border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td><img src="images/table_top_left.jpg" width="20" height="15" /></td>
            <td><img src="images/table_top_bg.jpg" width="770" height="15"/></td>
            <td align="right">
              <img src="images/table_top_right.jpg" width="20" height="15" /></td>
          </tr>
        </table>
      </td>
    </tr>
    <tr>
      <td height="25" colspan="3" class="table_blue">
        <strong><img src="images/dot.jpg" width="13" height="9">账号信息</strong></td>
    </tr> 
    <tr>
      <td class="table_w1" width="10%">&nbsp;<font color="red">(*)</font>ID：</td>
      <td class="table_w2" width="90%" colspan="2">&nbsp;
        <input id="act_id" type="text" size="60" 
          value="<s:property value="account.id" />" <s:if  test="type.equals('update')" >readonly="readonly"</s:if> /></td>
    </tr>
    <tr>
      <td class="table_w1">&nbsp;<font color="red">(*)</font>名称：</td>
      <td class="table_w2" colspan="2">&nbsp;
        <input id="act_name" type="text" size="60" 
          value="<s:property value="account.name" />" <s:if test="account.accountId.equals('admin')" >readonly="readonly"</s:if> /></td>
    </tr>
    <s:if test="account.id.length()>0">
        <input id="act_password" type="hidden" value="<s:property value="account.password" />" />
    </s:if>
    <s:else>
    <tr>
      <td class="table_w1">&nbsp;<font color="red">(*)</font>密码：</td>
      <td class="table_w2" colspan="2">&nbsp;
        <input id="act_password" type="text" size="60"
          value="<s:property value="account.password" />" />&nbsp;&nbsp;<button id="btn5" dojoType="dijit.form.Button"
            onclick="generate_passowrd('act_password');">随机密码</button></td>
    </tr>
    </s:else>
    <tr>
      <td class="table_w1">&nbsp;<font color="red">(*)</font>类型：</td>
      <td class="table_w2" colspan="2">&nbsp;
      <s:if test="!account.id.equals('admin')" ><select id="account_type" dojoType="dijit.form.FilteringSelect" style="width:290px;">
        <option value=""></option>
        <s:iterator value="%{getConstant('account type')}" status="stat1">
        <option value="<s:property value="key" />" 
            <s:if test="key.equals(account.type)" >selected</s:if> ><s:property value="value" /></option>
        </s:iterator>
      </select>
      </s:if>
      <s:else><input type="hidden" id="account_type" value="<s:property value="account.type" />" >系统管理员</s:else>
    </tr>
    <tr>
      <td class="table_w1">&nbsp;<font color="red">(*)</font>角色：</td>
      <td class="table_w2" colspan="2">&nbsp;
      <s:if test="!account.id.equals('admin')" ><select id="act_role" dojoType="dijit.form.FilteringSelect" style="width:290px;">
        <option value=""></option>
      <s:if test="roles.size()>0" >
        <s:iterator value="roles" status="stat">
        <option value="<s:property value="id" />" 
            <s:if test="id.equals(account.roleId)" >selected</s:if> ><s:property value="name" /></option>
        </s:iterator>
      </s:if>
      </select>
      </s:if>
      <s:else><input type="hidden" id="act_role" value="<s:property value="account.roleId" />" />系统管理员</s:else>
    </tr>
    <tr>
      <td class="table_w1">&nbsp;关联渠道：</td>
      <td class="table_w2" colspan="2">
      <s:if test="channels.size()>0">
        <table width="100%"  border="0" cellspacing="0" cellpadding="0">
          <tr>
          <s:iterator value="channels" status="stat2" id="pro">
            <s:if test="#stat2.index>0&&#stat2.index%5==0">
            </tr>
            </s:if>
            <td width="20%" align="left">
              &nbsp;&nbsp;<input type="checkbox" id="channelid" name="channelid" value="<s:property value="id"/>" 
                 <s:if test="channelIds.contains(id)">checked="checked"</s:if>
               />&nbsp;<s:property value="name"/>             
             </td>
            </s:iterator>
            <s:if test="channels.size()%5!=0">
              <td colspan="<s:property value="5-channels.size()%5" />">&nbsp;</td>
            </s:if>
            </tr>
         </table>
       </s:if>
       </td>
    </tr>
    <!-- tr>
      <td class="table_w1">&nbsp;关联商家：</td>
      <td class="table_w2" colspan="2">
      <s:if test="merchants.size()>0">
        <table width="100%"  border="0" cellspacing="0" cellpadding="0">
          <tr>
          <s:iterator value="merchants" status="stat2" id="pro">
            <s:if test="#stat2.index>0&&#stat2.index%5==0">
            </tr>
            </s:if>
            <td width="20%" align="left">
              &nbsp;&nbsp;<input type="checkbox" id="merchantid" name="merchantid" value="<s:property value="id"/>" 
                 <s:if test="merchantIds.contains(id)">checked="checked"</s:if>
               />&nbsp;<s:property value="name"/>             
             </td>
            </s:iterator>
            <s:if test="merchants.size()%5!=0">
              <td colspan="<s:property value="5-merchants.size()%5" />">&nbsp;</td>
            </s:if>
            </tr>
         </table>
       </s:if>
       </td>
    </tr-->
    
    <tr>
      <td class="table_w1">&nbsp;关联通道：</td>
      <td class="table_w2" colspan="2">
      <s:if test="spInfos.size()>0">
        <table width="100%"  border="0" cellspacing="0" cellpadding="0">
          <tr>
          <s:iterator value="spInfos" status="stat2" id="pro">
            <s:if test="#stat2.index>0&&#stat2.index%5==0">
            </tr>
            </s:if>
            <td width="20%" align="left">
              &nbsp;&nbsp;<input type="checkbox" id="spid" name="spid" value="<s:property value="id"/>" 
                 <s:if test="spIds.contains(id)">checked="checked"</s:if>
               />&nbsp;<s:property value="spName"/>             
             </td>
            </s:iterator>
            <s:if test="spInfos.size()%5!=0">
              <td colspan="<s:property value="5-spInfos.size()%5" />">&nbsp;</td>
            </s:if>
            </tr>
         </table>
       </s:if>
       </td>
    </tr>
    
    <tr>
      <td class="table_w1">&nbsp;关联CP：</td>
      <td class="table_w2" colspan="2">
      <s:if test="spInfos.size()>0">
        <table width="100%"  border="0" cellspacing="0" cellpadding="0">
          <tr>
          <s:iterator value="cpInfos" status="stat2" id="pro">
            <s:if test="#stat2.index>0&&#stat2.index%5==0">
            </tr>
            </s:if>
            <td width="20%" align="left">
              &nbsp;&nbsp;<input type="checkbox" id="cpid" name="cpid" value="<s:property value="id"/>" 
                 <s:if test="cpIds.contains(id)">checked="checked"</s:if>
               />&nbsp;<s:property value="cpName"/>             
             </td>
            </s:iterator>
            <s:if test="cpInfos.size()%5!=0">
              <td colspan="<s:property value="5-cpInfos.size()%5" />">&nbsp;</td>
            </s:if>
            </tr>
         </table>
       </s:if>
       </td>
    </tr>
    <tr>
      <td colspan="3" class="table_w1" align="center">
        <s:if test="type.equals('insert')">
        <button id="btn2" dojoType="dijit.form.Button"
            onclick="sys_saveaccount('insert');">添加</button>
        </s:if>
        <s:else>
        <button id="btn2" dojoType="dijit.form.Button"
            onclick="sys_saveaccount('update');">修改</button>
        <s:if test="account.type!=0">
        &nbsp;&nbsp;        
        <button id="btn3" dojoType="dijit.form.Button"
            onclick="sys_saveaccount('delete');">删除</button>
        </s:if>
        </s:else>
        &nbsp;&nbsp;        
        <button id="btn4" dojoType="dijit.form.Button"
            onclick="sys_listaccount();">返回</button>
      </td>      
    </tr>
    <tr> 
      <td colspan="7" background="images/table_bom_bg.jpg">
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td><img src="images/table_bom_left.jpg" width="20" height="15"></td>
          <td></td>
          <td align="right">
            <img src="images/table_bom_right.jpg" width="20" height="15"></td>
        </tr>
        </table>
      </td>
    </tr>
  </table>  
  </form>
  </td>
  <td width="5"></td>
  </tr>
  </table>